﻿$(document).ready(function() {
    var community = new Chenxin.UI.CommunityMgr({
		createGrid:function(){			
			return new Chenxin.UI.ExpandGrid({
				actionUrl:this.actionUrl+'?op=getlist',
				id:'community',
				renderTo:'community_table',
				hasCheckBox:false,
				columns:{
					CommunityName:{
						head:'楼盘名称',
						width:130,
						sortable:true
					},
					Region:{
						head:'区域',
						width:80,
						sortable:true
					},
					Block:{
						head:'板块',
						width:60,
						sortable:true
					},
					Address:{
						head:'地址',
						width:130,
						sortable:true
					},
					CommunityUse:{
						head:'用途',
						width:60,
						sortable:true
					},
					BuildingType:{
						head:'类型',
						width:55,
						sortable:true
					},
					CompleteYear:{
						head:'竣工年份',
						width:70,
						sortable:true
					},
					AddTime:{
						head:'开盘时间',
						width:120,
						sortable:true
					},
					Status:{
						head:'状态',
						width:60,
						sortable:true,
						style:'text-align:center;'
					}
				},
				scope:this,
				rowExpandAble:true,
				rowExpand:function(dom,el,grid){
					dom.append('<div class="g_box"><div class="g_tab1"><div id="communitybuilding_table"></div></div></div>');
					this.createHouseBuilding();
					this.buildIngMgr.grid.reload({
						communityid:this.currentId
					},true);	
				}
			});
		},
		loadHouseBuilding: function() {
			if (!this.currentId) {
				alert('请先选择一条楼盘记录！')
				return;
			}
			$('#' + this.currentId).after('<tr id="tr_communitybuilding" n="'+this.currentId+'"><td colspan="10" class="gendan_box" valign="top" style="padding-top:5px;padding-left:5px;  " ><div class="g_box"><div class="g_tab1"><div id="communitybuilding_table"></div></div></div></td></tr>');
			this.createHouseBuilding();
			this.buildIngMgr.grid.reload({
				communityid: this.currentId
			}, true);
		},
		createHouseBuilding: function() {
			if (!this.buildIngMgr) {
				this.buildIngMgr = new Chenxin.UI.CommunityBuildingMgr({
					autoLoadGrid: false
				});
				this.buildIngMgr.grid.pageSize=100
				this.buildIngMgr.grid.afterRender=function(data){
					if(data.count){
						$('.x-grid-row-expand').height(80+25*data.count);					
					}else{
						$('.x-grid-row-expand').height(180);						
					}
				}
			}
			if (this.currentId) {
				this.buildIngMgr.communityId = this.currentId;
			}
		}
	});

})